<?php

namespace App\Models;

use App\Models\Traits\CommentCacheTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Comment
 *
 * @property int $id
 * @property int $user_id
 * @property int $commentable_id
 * @property string $commentable_type
 * @property string|null $content
 * @property array|null $images
 * @property int $is_checked
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read Model|\Eloquent $commentable
 * @property-read \App\Models\User $user
 * @method static \Database\Factories\CommentFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Comment newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Comment query()
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereCommentableId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereCommentableType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereImages($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereIsChecked($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereUserId($value)
 * @mixin \Eloquent
 * @property bool $is_favor
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereIsFavor($value)
 */
class Comment extends Model
{
    use HasFactory;
    use CommentCacheTrait;
    
    protected $guarded = ['id'];
	
	protected $casts = [
		'images' => 'json',
		'is_favor' => 'boolean',
	];
    
    public function commentable()
    {
    	return $this->morphTo();
    }
	
	public function user()
	{
		return $this->belongsTo(User::class);
	}
}
